import java.util.Arrays;

public class insertionSort {
    public static void sort(int[] nums){
        if(nums.length == 0 || nums == null){
            return;
        }
        for (int i = 1; i < nums.length; i++) {
            int tmp = nums[i];
            int j;
            for(j = i; j > 0; j--){
                if(tmp < nums[j-1]){
                    nums[j] = nums[j-1];
                }else {
                    break;
                }
            }
            nums[j] = tmp;
        }
    }
    public static void sort1(int[] nums){
        if(nums.length == 0 || nums == null){
            return;
        }
        for (int i = 1; i < nums.length; i++) {
            for(int j = i; j > 0; j--){
                if(nums[j] < nums[j-1]){
                    swap(nums,j,j-1);
                }else {
                    break;
                }
            }
        }
    }
    private static void swap(int[] nums, int minIndex, int i){
        int tmp = nums[minIndex];
        nums[minIndex] = nums[i];
        nums[i] = tmp;
    }
    public static void main(String[] str){
        int[] nums = {22,31,2,1,5,10};
        sort(nums);
        System.out.println(Arrays.toString(nums));
    }
}
